#include<stdio.h>
#include<unistd.h>
#include <sys/wait.h>
#include<sys/types.h>

void func()
{
	while(1)
	{
		printf("我是一个子进程\n");
		sleep(1);
	}
}


int main(int argc ,char * argv[])
{
	pid_t pid = fork();

	if(pid == 0)
	{
		func();
	}
	else if(pid > 0)
	{   while(1)
		{
			int status = 0;
			pid_t ret = waitpid(-1, &status, WNOHANG);//非阻塞等待

			if(ret > 0)
			{
				printf("等待成功\n");
				break;
			}
			else if(ret < 0)
			{
				printf("等待子进程失败\n");
			}
			else
			{
				printf("进程还没退出\n");
			}
		sleep(1);
		}
	}
	return 0;
}
